package com.rr.mymoney.dao.impl.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rr.mymoney.dao.CurrencyDao;
import com.rr.mymoney.model.Currency;

@Transactional
@Repository
public class CurrencyDaoImpl extends AbstractDao implements CurrencyDao {
    public void saveOrUpdate(Currency currency) {
	getCurrentSession().saveOrUpdate(currency);
	getCurrentSession().flush();
	getCurrentSession().evict(currency);
    }

    public Currency get(Long id) {
	return (Currency) getCurrentSession().get(Currency.class, id);
    }

    public void delete(Currency currency) {
	getCurrentSession().delete(currency);
    }

    public List<Currency> getAll() {
	Query query = getCurrentSession().createQuery("from Currency order by label");
	return query.list();
    }
}
